﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using Mengsk.ERP.Orders;

namespace Mengsk.ERP.App.AddressCheck
{
    class OrderViewModel : DependencyObject
    {
        public static readonly DependencyProperty FlagProperty = DependencyProperty.Register("Flag", typeof(BitmapSource), typeof(OrderViewModel));
        public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register("Background", typeof(Brush), typeof(OrderViewModel));
        public static readonly DependencyProperty OrderProperty = DependencyProperty.Register("Order", typeof(Mengsk.ERP.Orders.Order), typeof(OrderViewModel));
        public static readonly DependencyProperty SellerCommentProperty = DependencyProperty.Register("SellerComment", typeof(string), typeof(OrderViewModel));

        public string Shop
        {
            get
            {
                if (this.Order == null)
                {
                    return "";
                }

                if (this.Order.Shop == Mengsk.ERP.Orders.Shop.PAIPAI_YIMEIER)
                {
                    return "拍拍_伊";
                }

                if (this.Order.Shop == Mengsk.ERP.Orders.Shop.TAOBAO_SHANGMEIQI)
                {
                    return "淘宝_梦";
                }

                if (this.Order.Shop == Mengsk.ERP.Orders.Shop.TMALL_MOSIGE)
                {
                    return "天猫_梦";
                }

                if (this.Order.Shop == Mengsk.ERP.Orders.Shop.WANGGOU_MOSIGE)
                {
                    return "网购_梦";
                }

                if (this.Order.Shop == Mengsk.ERP.Orders.Shop.WANGGOU_SHANGMEIQI)
                {
                    return "网购_尚";
                }
                return this.Order.Shop.ToString();
            }
        }

        public string Item
        {
            get
            {
                if (this.Order == null)
                {
                    return "";
                }

                return this.Order.Items[0].InternalName + " " + this.Order.Items[0].Edtion + " " + this.Order.Items[0].Color + " " + this.Order.Items[0].Size + " " + this.Order.Money + "元" + string.Format("( X {0})", this.Order.Items[0].Count);
            }
        }

        public Visibility RowDetailVisibility { get { return this.Order.Items.Count > 1 ? Visibility.Visible : Visibility.Collapsed; } }

        public BitmapSource Flag { get { return (BitmapSource)this.GetValue(FlagProperty); } set { this.SetValue(FlagProperty, value); } }

        public string SellerComment { get { return (string)this.GetValue(SellerCommentProperty); } set { this.SetValue(SellerCommentProperty, value); this.Order.SellerComment = value; } }

        public string Expander
        {
            get
            {
                string expander = this.Order.Items.Count > 1 ? "多" : "";

                if (this.HistoryOrder != null && this.HistoryOrder.Length > 0)
                {
                    expander += " 史";
                }

                return expander;
            }
        }

        public Brush Background { get { return (Brush)this.GetValue(BackgroundProperty); } set { this.SetValue(BackgroundProperty, value); } }

        public Order Order { get { return (Order)this.GetValue(OrderProperty); } set { this.SetValue(OrderProperty, value); } }

        public string State
        {
            get
            {
                if (this.Order == null)
                {
                    return "错误";
                }

                if ("DS_UNKNOWN".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "系统处理中,未知状态";
                }
                else if ("DS_WAIT_BUYER_PAY".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待买家付款";
                }
                else if ("DS_WAIT_SELLER_DELIVERY".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家发货";
                }
                else if ("DS_BUYER_PAID_CFT".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "买家已生成财付通支付单号";
                }
                else if ("DS_WAIT_BUYER_RECEIVE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "卖家已发货";
                }
                else if ("DS_DEAL_CANCELLED".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "订单取消";
                }
                else if ("DS_DEAL_SHIPPING_PREPARE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "卖家配货中";
                }
                else if ("DS_DEAL_REFUNDING".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "退款处理中";
                }
                else if ("DS_DEAL_END_REFUND".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "订单退款结束";
                }
                else if ("DS_DEAL_END_NORMAL".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "交易成功";
                }
                else if ("DS_BUYER_EVALUATED".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "买家已评价";
                }
                else if ("DS_REFUND_START".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "开始退款流程";
                }
                else if ("DS_REFUND_WAIT_BUYER_DELIVERY".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待买家发送退货";
                }
                else if ("DS_REFUND_WAIT_SELLER_RECEIVE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家确认收货";
                }
                else if ("DS_REFUND_WAIT_SELLER_AGREE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家同意退款";
                }
                else if ("DS_REFUND_OK".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "退款成功";
                }
                else if ("DS_REFUND_CANCEL".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "退款取消";
                }
                else if ("DS_REFUND_ALL_WAIT_SELLER_AGREE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家同意全额退款";
                }
                else if ("DS_REFUND_WAIT_MODIFY".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待买家修改退款申请";
                }
                else if ("DS_REFUND_ALL_CANCEL".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "全额退款取消";
                }
                else if ("DS_REFUND_ALL_OK".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "全额退款成功";
                }
                else if ("DS_TIMEOUT_BUYER_RECEIVE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待买家确认收货超时";
                }
                else if ("DS_TIMEOUT_SELLER_RECEIVE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家确认收货超时";
                }
                else if ("DS_TIMEOUT_SELLER_PASS_RETURN".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家响应买家退货请求超时";
                }
                else if ("DS_TIMEOUT_SELLER_PASS_REFUND_ALL".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "等待卖家确认全额退款超时";
                }
                else if ("DS_CLOSED".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "订单已关闭";
                }
                else if ("DS_UNKNOWN".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "系统处理中";
                }
                else if ("STATE_COD_START".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款开始";
                }
                else if ("STATE_COD_WAIT_SHIP".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款等待发货";
                }
                else if ("STATE_COD_SHIP_OK".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款已发货";
                }
                else if ("STATE_COD_SIGN".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款已签收";
                }
                else if ("STATE_COD_REFUSE".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款拒签";
                }
                else if ("STATE_COD_SUCESS".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款成功";
                }
                else if ("STATE_COD_CANCEL".Equals(this.Order.State, StringComparison.OrdinalIgnoreCase))
                {
                    return "货到付款取消";
                }
                else
                {
                    return this.Order.State;
                }

            }
        }

        public string Phone
        {
            get
            {
                if (Order == null)
                {
                    return "";
                }
                if (string.IsNullOrWhiteSpace(Order.PhoneMobile) == false)
                {
                    return Order.PhoneMobile;
                }
                return Order.Phone;
            }
        }

        public string PhoneAddress { get; set; }

        public OrderViewModel[] HistoryOrder { get; set; }

        public string HistoryDeliverCompany { get; set; }



    }
}
